<?php

namespace app\supplier\controller\stall;

use app\supplier\controller\Controller;
use app\supplier\model\stall\Apply as ApplyModel;

/**
 * 摊位控制器
 */
class Stall extends Controller
{

    /**
     * 申请列表
     */
    public function index()
    {
        $model = new ApplyModel;
        $list  = $model->getList($this->postData(),$this->getSupplierId());
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * 审核
     */
    public function audit($apply_id)
    {
        $model = ApplyModel::getdetail($apply_id);
        if ($model->audit($this->postData())) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');

    }

    /**
     * 添加
     */
    public function add()
    {
        $model = new ApplyModel;
        if ($this->request->isGet()) {
            return $this->renderSuccess('', []);
        }
        // 新增记录
        if ($model->add($this->postData())) {
            return $this->renderSuccess('', '添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }


    /**
     * 编辑
     */
    public function edit($apply_id)
    {
        $model = ApplyModel::getdetail($apply_id);
        if ($this->request->isGet()) {
            return $this->renderSuccess('', compact('model'));
        }
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('', '更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }

    /**
     * 删除
     */
    public function delete($apply_id)
    {
        // 详情
        $model = ApplyModel::getdetail($apply_id);
        if (!$model->delete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('', $model->getError() ?: '删除成功');
    }

}